package org.jsola.hr.helper;

import org.jsola.hr.dto.ZtcConfigAddDTO;
import org.jsola.hr.dto.ZtcConfigUpdateDTO;
import org.jsola.hr.entity.ZtcConfigDO;
import org.jsola.hr.query.ZtcConfigQuery;
import org.jsola.hr.service.IZtcConfigService;
import org.jsola.hr.vo.ZtcConfigVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 政企直通车配置
 *
 * @author zhr
 */
@Component
public class ZtcConfigTestHelper extends BaseTestHelper {
    
    @Autowired
    private IZtcConfigService ztcConfigService;

    /**
     * 生成add测试数据
     * @return ZtcConfigAddDTO
     */
    public ZtcConfigAddDTO getZtcConfigAddDTO(){
        ZtcConfigAddDTO ztcConfigAddDTO = new ZtcConfigAddDTO();
        ztcConfigAddDTO.setAppId(getRandomValue("varchar",32));
        ztcConfigAddDTO.setOfficialKey(getRandomValue("varchar",32));
        ztcConfigAddDTO.setSiteName(getRandomValue("varchar",50));
        ztcConfigAddDTO.setRelevancyCompanyId(getRandomValue("text",2147483647));
        ztcConfigAddDTO.setRelevancyCompanyName(getRandomValue("text",2147483647));
        ztcConfigAddDTO.setName(getRandomValue("varchar",50));
        ztcConfigAddDTO.setRemark(getRandomValue("varchar",255));
        return ztcConfigAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ZtcConfigUpdateDTO
     */
    public ZtcConfigUpdateDTO getZtcConfigUpdateDTO(ZtcConfigVO ztcConfigVO){
        return ztcConfigService.selectDOById(ztcConfigVO.getId(), SITE_ID).to(ZtcConfigUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ZtcConfigQuery
     */
    public ZtcConfigQuery getZtcConfigQuery() {
        ZtcConfigQuery ztcConfigQuery = new ZtcConfigQuery();
        List<ZtcConfigDO> ztcConfigDOList = ztcConfigService.list(new ZtcConfigDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(ztcConfigDOList)) {
            ZtcConfigDO ztcConfigDO = ztcConfigDOList.get(0);
            ztcConfigQuery = ztcConfigDO.to(ZtcConfigQuery.class);
        }
        return ztcConfigQuery;
    }

    /**
     * 保存示例
     * @return ZtcConfigVO
     */
    public ZtcConfigVO saveZtcConfigExample(){
        ZtcConfigAddDTO addDTO = this.getZtcConfigAddDTO();
        ZtcConfigVO ztcConfigVO = ztcConfigService.save(addDTO,buildTokenUser());
        return ztcConfigVO;
    }


}

